#!/bin/bash

VERSION=1.1
ARCH=`uname -m`
KERNEL=`uname -r`

LIB_NAME="libxbase-${KERNEL}-${ARCH}-${VERSION}.a"

LIB_HEADERS="*.hpp"

COMMON_DIR="../common"
COMMON_HEADERS="atomic.h binary_iarchive.hpp binary_oarchive.hpp byteorder.hpp compressor.hpp compressor_minilzo.hpp compressor_bmz.hpp compressor_zlib.hpp compressor_quicklz.hpp config.hpp constants.hpp dynamic_buffer.hpp error_code.hpp stringable.hpp throw_error.hpp uuid.hpp version.hpp xbase_utility.hpp wrapper.hpp intrusive_ptr_helper.hpp stack_or_heap_array.hpp minilzo quicklz bmz detail"

OBJS="*.o $COMMON_DIR/*.o"

CUR_PATH=`pwd`
DEST_PATH="/tmp/$$/xbase-lib/xbase"

rm -rf /tmp/$$
mkdir -p $DEST_PATH

cp $LIB_HEADERS $DEST_PATH
cd $COMMON_DIR
cp -R $COMMON_HEADERS $DEST_PATH

rm -rf /tmp/$$/xbase-lib/xbase/*/.svn
rm -rf /tmp/$$/xbase-lib/xbase/*/*/.svn

cd $CUR_PATH
ar cr /tmp/$$/xbase-lib/${LIB_NAME} ${OBJS}

cd /tmp/$$
cd xbase-lib
ln -sf ${LIB_NAME} libxbase.a
cd ..
tar zcf xbase-lib.tar.gz xbase-lib

cd $CUR_PATH
mv /tmp/$$/xbase-lib.tar.gz .
rm -rf /tmp/$$

